package com.yale.email.service;

import com.yale.spring.cloud.commons.model.MailInfo;
import com.yale.spring.cloud.feigin.api.MailService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

/**
 * @author yale
 */
@RefreshScope
@DubboService
public class MailServiceImpl implements MailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${mail.fromMail.addr}")
    private String from;


    @Override
    public void sendEmail(MailInfo mailInfo) {
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(mailInfo.getTo());
        message.setSubject(mailInfo.getSubject());
        message.setText(mailInfo.getContent());
        javaMailSender.send(message);
    }
}
